package net.qiqbframework.event.dao.mpimpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.qiqbframework.common.dto.PageResultDto;
import net.qiqbframework.eventsourcing.dao.DomainEventSubscriptionDao;
import net.qiqbframework.eventsourcing.dao.DomainEventSubscriptionPageCondition;
import net.qiqbframework.eventsourcing.dao.DomainEventSubscriptionPo;
import net.qiqbframework.mp.BasicEntityPoDaoMpImpl;
import net.qiqbframework.mp.MpUtil;

import java.util.List;

public class DomainEventSubscriptionDaoMpImpl extends BasicEntityPoDaoMpImpl<DomainEventSubscriptionMapper, DomainEventSubscriptionPo> implements DomainEventSubscriptionDao {
    @Override
    public PageResultDto<DomainEventSubscriptionPo> list4Page(DomainEventSubscriptionPageCondition condition) {
        QueryWrapper<DomainEventSubscriptionPo> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .eq(DomainEventSubscriptionPo::getEventId, condition.getEventId())
                .like(StringUtils.isNotEmpty(condition.getApplicationName()), DomainEventSubscriptionPo::getApplicationName, condition.getApplicationName())
                .like(StringUtils.isNotEmpty(condition.getInstanceName()), DomainEventSubscriptionPo::getInstanceName, condition.getInstanceName())

        ;
        final Page<DomainEventSubscriptionPo> page = super.page(MpUtil.ofPage(condition), queryWrapper);
        return MpUtil.toResult(page);
    }

    @Override
    public List<DomainEventSubscriptionPo> listByEventId(String eventId) {
        QueryWrapper<DomainEventSubscriptionPo> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(DomainEventSubscriptionPo::getEventId, eventId)

        ;
        return super.list(queryWrapper);
    }

}
